<?php
/**
 * Realty Controller
 *
 * @категория:  View
 * @пакет:      Croogo.Categories.Controller.View.Admin_Index
 * @версия:     1.0
 * @автор:      Калистратов Сергей Михайлович
 * @почта:      kalistratov.s.m@gmail.com
 * @телефон:    +7 (987) 310-56-02
 * @ссылка:     http://www.croogo.org
 */

$this->Html
	->addCrumb('', '/admin', array('icon' => 'home'))
	->addCrumb(__d('croogo', __d('croogo' , 'Categories')), array('plugin' => 'realty', 'controller' => 'categories', 'action' => 'index'));
?>
<div class="row-fluid">
	<div class="span12 actions">
		<ul class="nav-buttons">
			<?php
			echo $this->Croogo->adminAction(
				__d('croogo', 'Создать категорию'),
				array('action' => 'add'),
				array('button' => 'success')
			);
			?>
		</ul>
	</div>
</div>
<?php
echo $this->Form->create('Category', array(
	'url' => array(
		'plugin' => 'realty',
		'controller' => 'categories' ,
		'action' => 'process',
	),
));
?>
<table class="table table-striped">
	<thead>
	<?php
	$tableHeaders = $this->Html->tableHeaders(array(
		$this->Form->checkbox('selectAll' , array(
			'data-title'    => __d('croogo' , 'Select all') ,
			'rel'           => 'tooltip' ,
			'data-placement'=> 'right' ,
			'data-trigger'  => 'hover'
		)),
		__d('croogo' , 'Id'),
		__d('croogo' , 'Title'),
		__d('croogo' , 'Status'),
		__d('croogo' , 'Actions'),
	));
	echo $tableHeaders;
	?>
	</thead>
	<?php
	$rows = array();
	foreach ($categoriesTree as $CategoryId => $CategoryTitle) {

		$actions = array();

		$actions[] = $this->Croogo->adminRowAction('', array(
			'controller' => 'categories', 'action' => 'moveup', $CategoryId
		), array(
			'icon' => 'arrow-up',
			'tooltip' => __d('croogo', 'Поднять'),
		));

		$actions[] = $this->Croogo->adminRowAction('', array(
			'controller' => 'categories', 'action' => 'movedown', $CategoryId,
		), array(
			'icon' => 'arrow-down',
			'tooltip' => __d('croogo', 'Опустить'),
		));

		$actions[] = $this->Croogo->adminRowActions($CategoryId);

		$actions[] = $this->Croogo->adminRowAction('', array(
			'controller' => 'categories', 'action' => 'edit', $CategoryId,
		), array(
			'icon' => 'pencil', 'tooltip' => __d('croogo', 'Изменить категорию'),
		));

		$actions[] = $this->Croogo->adminRowAction(
			'',
			array('controller' => 'categories', 'action' => 'delete', $CategoryId),
			array('icon' => 'trash', 'tooltip' => __d('croogo', 'Удалить категорию')),
			__d('croogo', 'Are you sure?')
		);

		$actions = $this->Html->div('item-actions', implode(' ', $actions));

		$categoriesStatus[$CategoryId] = ($categoriesStatus[$CategoryId]) ? 1 : 0 ;

		$url = array(
			'admin' => true,
			'plugin' => 'realty',
			'controller' => 'categories',
			'action' => 'toggle',
			$CategoryId,
			$categoriesStatus[$CategoryId],
		);

		$rows[] = array(
			$this->Form->checkbox('Category.' . $CategoryId . '.id' , array('id' => 'checkbox')),
			$CategoryId,
			$CategoryTitle,
			$this->Html->status($categoriesStatus[$CategoryId], $url),
			$actions,
		);
	}
	echo $this->Html->tableCells($rows);
	?>
</table>

<div class="row-fluid">
	<div id="bulk-action" class="control-group">
		<?php
		echo $this->Form->input('Category.action', array(
			'div' => 'input inline',
			'label' => false,
			'options' => array(
				'publish' => __d('croogo', 'Publish'),
				'unpublish' => __d('croogo', 'Unpublish'),
				'delete' => __d('croogo', 'Delete'),
			),
			'empty' => true,
		));
		?>
		<div class="controls">
			<?php echo $this->Form->end(__d('croogo', 'Submit')); ?>
		</div>
	</div>
</div>

